package com.qf.web.blog.controller;

import com.qf.aop.async.AsyncTaskFactory;
import com.qf.api.blog.service.ArticleService;
import com.qf.api.front.dto.ArticleContent;
import com.qf.api.front.vo.ArticleVO;
import com.qf.api.sys.mybatis.page.BaseController;
import com.qf.api.sys.mybatis.page.PageResult;
import com.qf.core.response.ResponseResult;
import com.qf.core.thread.ThreadPoolManager;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: sin
 * @Date: 2025/5/31 0:16
 * @Description:
 **/
@Tag(name = "01.文章管理")
@RestController
@RequestMapping("/blog/article")
public class ArticleController extends BaseController {
    @Autowired
    private ArticleService articleService;

    @Autowired
    private AsyncTaskFactory asyncTaskFactory;

    @GetMapping
    public ResponseResult<PageResult<ArticleVO>> getPageArticle(@RequestParam(name = "title", required = false) String title,
                                                                @RequestParam(name = "tagId", required = false) Long tagId,
                                                                @RequestParam(name = "categoryId", required = false) Long categoryId) {
        startPage();
        List<ArticleVO> list = articleService.getPageArticle(title,tagId,categoryId);
        return ResponseResult.success(getData(list));
    }

    @GetMapping("/{articleId}")
    public ResponseResult<ArticleContent> getArticleContent(@PathVariable Long articleId) {
        ArticleContent articleContent = articleService.getArticleContent(articleId);
        ThreadPoolManager.execute(asyncTaskFactory.recordArticleVisit(articleId));
        return ResponseResult.success(articleContent);
    }
}
